import { BetaSchemaForm } from '@ant-design/pro-form'
import { PageContainer } from '@ant-design/pro-layout'
import { useAxiosWebGet, useAxiosWebPost } from '@sker/sdk'
import { renderAdminPage } from '@sker/ui'
import { Form } from 'antd'
import { useEffect } from 'react'
export const AccountPage: React.FC<{}> = ({ }) => {
    const { fetch: getSetting } = useAxiosWebGet('imeepos/core/addon/setting')
    const { fetch: saveSetting } = useAxiosWebPost('imeepos/core/addon/setting')
    const [form] = Form.useForm()
    useEffect(() => {
        getSetting({ name: '@imeepos/s3' }).then(res => res.data).then(res => form.setFieldsValue(res))
    }, [])
    return <PageContainer title={'S3参数设置'}>
        <BetaSchemaForm
            columns={[
                {
                    title: 'apiVersion',
                    dataIndex: 'apiVersion',
                    tooltip: '2006-03-01'
                }, {
                    title: 'region',
                    dataIndex: 'region',
                    tooltip: 'cn-north-1'
                }, {
                    title: 'endpoint',
                    dataIndex: 'endpoint',
                }, {
                    title: 'accessKeyId',
                    dataIndex: 'accessKeyId'
                }, {
                    title: 'secretAccessKey',
                    dataIndex: 'secretAccessKey'
                }, {
                    title: '私有空间',
                    dataIndex: 'privateBucket'
                }, {
                    title: '公共空间',
                    dataIndex: 'publicBucket'
                }
            ]}
            form={form}
            onFinish={async values => {
                saveSetting({
                    name: '@imeepos/s3',
                    setting: values
                })
            }} />
    </PageContainer>
}
renderAdminPage(AccountPage, 'imeepos/s3/web/setting')
